﻿<div ng-controller="FieldManDetailC">
    <div class="modal fade" id="dlg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form name="myform1">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">更改送货信息</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label>车辆信息(每条信息以英文逗号分隔)</label>
                            <input type="text" ng-pattern="/^[a-zA-Z0-9\u4e00-\u9fa5,]+$/" class="form-control" ng-model="orderdetaildata.VehicleInfos">
                        </div>
                        <div class="form-group">
                            <label>联系人(每条信息以英文逗号分隔)</label>
                            <input type="text" ng-pattern="/^[a-zA-Z0-9\u4e00-\u9fa5,]+$/" class="form-control" ng-model="orderdetaildata.Contact">
                        </div>
                        <div class="form-group">
                            <label>联系人手机号(每条信息以英文逗号分隔)</label>
                            <input type="text" ng-pattern="/^[0-9,]+$/" class="form-control" ng-model="orderdetaildata.ContactPhone">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-success" ng-disabled="myform1.$invalid" ng-click="okchange()">确认提交</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="modal fade" id="shangchuan" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form id="myupload" action={{myurl}} method="post" enctype="multipart/form-data">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabe2">上传收货凭证 </h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group btn">
                            <!--<input type="label" name="label" id="label" class="form-control" placeholder="请选择文件" /><br />-->
                            <label style="margin-right: 10px;">请选择文件</label>
                            <input type="file" accept=".jpg,.jpeg,.png" name="file1" id="fileupload" class="form-control" value="" /><br />
                        </div>
                        <div class="progress">
                            <span class="bar"></span><span class="percent">0%</span>
                        </div>
                        <!-- 显示已上传的文件名 -->
                        <div class="files"></div>
                        <!-- 显示已上传的图片-->
                        <div class="showimg"></div>
                    </div>
                    <div class="modal-footer">
                        <!--<button type="button" class="btn btn-success" ng-disabled="myform1.$invalid" ng-click="okchange()">确认提交</button>-->
                        <input type="button" class="btn btn-default" ng-click="gosubmit2()" value="提交" />
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="modal fade" id="tupian" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <!--<h4 class="modal-title" id="myModalLabe3">收货凭证 </h4>-->
                <!--<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>-->
                <img style="width: 100%;" ng-src="/file/{{editReceiptdata}}" alt="收货凭证">
            </div>
        </div>
    </div>
    <!--<iframe id="id_iframe" name="nm_iframe" style="display:none;"></iframe>-->
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">驻厂计划单详情---
            <span ng-if="orderdetaildata.OrderType == 0">普通订单</span>
            <span ng-if="orderdetaildata.OrderType == 1">商品锁价</span>
            <span ng-if="orderdetaildata.OrderType == 2">基价锁价</span>
            <span ng-if="orderdetaildata.OrderType == 3">自采订单</span>
            <span ng-if="orderdetaildata.OrderType == 4">库提销售</span></h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="form-group">
                                <label>客户</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="orderdetaildata.Customer.Name">
                            </div>
                            <div class="form-group">
                                <label>客户经理</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="orderdetaildata.Creater.Name">
                            </div>
                            <div class="form-group">
                                <label>公司户头</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="orderdetaildata.Account.Name">
                            </div>
                            <div class="form-group">
                                <label>区域</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="orderdetaildata.District.FillName">
                            </div>
                            <div class="form-group">
                                <label>具体地址</label>
                                <input type="text" class="form-control" ng-model="orderdetaildata.Address">
                            </div>
                            <div class="form-group">
                                <label for="xiankuan" style="margin-right: 10px;">是否先款</label>
                                <label class="i-checks">
                                    <input type="checkbox" id="xiankuan" disabled="disabled" ng-model="orderdetaildata.IsFullPayment">
                                    <i></i>
                                </label>
                                <label for="biaojian" style="margin-right: 10px;">是否标件</label>
                                <label class="i-checks">
                                    <input type="checkbox" id="biaojian" disabled="disabled" ng-model="orderdetaildata.IsStandard">
                                    <i></i>
                                </label>
                                <label for="biaojian" style="margin-right: 10px;">是否锁价</label>
                                <label class="i-checks">
                                    <input type="checkbox" id="biaojian" disabled="disabled" ng-model="orderdetaildata.IsLockPrice">
                                    <i></i>
                                </label>
                                <label for="zipai" style="margin-right: 10px;">是否自派</label>
                                <label class="i-checks">
                                    <input type="checkbox" id="zipai" disabled="disabled" ng-model="orderdetaildata.IsDelivery">
                                    <i></i>
                                </label>
                            </div>
                            <!--<div class="form-group">-->
                                <!--<label for="biaojian" style="margin-right: 10px;">是否标件</label>-->
                                <!--<label class="i-checks">-->
                                    <!--<input type="checkbox" id="biaojian" disabled="disabled" ng-model="orderdetaildata.IsStandard">-->
                                    <!--<i></i>-->
                                <!--</label>-->
                            <!--</div>-->
                            <!--<div class="form-group">-->
                                <!--<label for="zipai" style="margin-right: 10px;">是否自派</label>-->
                                <!--<label class="i-checks">-->
                                    <!--<input type="checkbox" id="zipai" disabled="disabled" ng-model="orderdetaildata.IsDelivery">-->
                                    <!--<i></i>-->
                                <!--</label>-->
                            <!--</div>-->
                            <div class="form-group" ng-if="orderdetaildata.IsDelivery">
                                <label style="margin-right: 10px;">运费是否公户</label>
                                <label class="i-checks">
                                    <input type="checkbox" disabled="disabled" ng-model="orderdetaildata.IsPublicDelivery">
                                    <i></i>
                                </label>
                            </div>
                            <div class="form-group" ng-if="!orderdetaildata.IsDelivery">
                                <label>运费合计</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="orderdetaildata.DeliveryPriceTotal">
                            </div>
                            <div class="form-group" ng-if="orderdetaildata.IsDelivery">
                                <label>车辆信息(每条信息以英文逗号分隔)</label>
                                <input type="text" ng-pattern="/^[a-zA-Z0-9\u4e00-\u9fa5,]+$/" class="form-control" readonly="readonly" ng-model="orderdetaildata.VehicleInfos">
                            </div>
                            <div class="form-group" ng-if="orderdetaildata.IsDelivery">
                                <label>联系人(每条信息以英文逗号分隔)</label>
                                <input type="text" ng-pattern="/^[a-zA-Z0-9\u4e00-\u9fa5,]+$/" class="form-control" readonly="readonly" ng-model="orderdetaildata.Contact">
                            </div>
                            <div class="form-group" ng-if="orderdetaildata.IsDelivery">
                                <label>联系人手机号(每条信息以英文逗号分隔)</label>
                                <input type="text" ng-pattern="/^[0-9,]+$/" class="form-control" readonly="readonly" ng-model="orderdetaildata.ContactPhone">
                            </div>
                            <div class="form-group">
                                <label>备注</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="orderdetaildata.Remarks">
                            </div>
                            <div class="form-group">
                                <label>申请单价优惠</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="orderdetaildata.ApplyDiscount">
                            </div>
                            <div class="form-group">
                                <label>申请总价优惠</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="orderdetaildata.BargainingAmount">
                            </div>
                            <div class="form-group">
                                <label>供应商</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="orderdetaildata.Provider.Name">
                            </div>
                            <!--<div class="form-group">-->
                                <!--<label>变更记录</label>-->
                                <!--<ul>-->
                                    <!--<li ng-repeat="item in orderdetaildata.Records | orderBy:['CreateTime']">-->
                                        <!--{{item.CreateTime}}/<label ng-if="item.Price != 0">{{item.Price}}/</label>{{item.Remarks}}-->
                                    <!--</li>-->
                                <!--</ul>-->
                            <!--</div>-->
                            <div class="form-group">
                                <accordion close-others="oneAtATime">
                                    <accordion-group heading="查看历史记录➤">
                                        <ul>
                                            <li ng-repeat="item in orderdetaildata.Records | orderBy:['CreateTime']">
                                                {{item.CreateTime}}/<label ng-if="item.Price != 0">{{item.Price | number:2}}/</label>{{item.Remarks}}
                                            </li>
                                        </ul>
                                    </accordion-group>
                                </accordion>
                            </div>
                            <div class="form-group">
                                <label>订单状态：</label>
                                <span style="width:10%" ng-if="orderdetaildata.State == 0">待确认</span>
                                <span style="width:10%" ng-if="orderdetaildata.State == 1">驻厂确认</span>
                                <span style="width:10%" ng-if="orderdetaildata.State == 2">已发货</span>
                                <span style="width:10%" ng-if="orderdetaildata.State == 3">已收货</span>
                                <span style="width:10%" ng-if="orderdetaildata.State == 4">已结算</span>
                                <span style="width:10%" ng-if="orderdetaildata.State == 5">完结</span>
                                <span style="width:10%" ng-if="orderdetaildata.State == 6">取消</span>
                                <span style="width:10%" ng-if="orderdetaildata.State == 7">审核通过</span>
                                <span style="width:10%" ng-if="orderdetaildata.State == 8">已退货</span>
                                <span style="width:10%" ng-if="orderdetaildata.State == 9">已退款</span>
                            </div>
                            <div class="form-group" ng-if="GetReceiptdata">
                                <label>收货凭证：</label>
                                <img style="height: 50px; margin: 10px" ng-repeat="item in GetReceiptdata track by $index" ng-src="/file/{{item}}" alt="收货凭证" ng-click="editReceipt(item)" data-toggle="modal" data-target="#tupian">
                            </div>
                        </div>
                        <div class="container-fluid text-center bg-light lter" >
                            <div class="row">
                                <h3 style="display: inline-block;margin: 0 auto">订单商品列表</h3>
                            </div>
                        </div>
                        <div class="container-fluid" style="margin-top: 10px">
                            <div class="panel panel-default" ng-repeat="item in orderdetaildata.CommodityInfos" style="margin-bottom: 10px">
                                <div class="panel-heading">
                                    <div>品牌：{{item.Commodity.Brand}}</div>
                                </div>
                                <div class="panel-body">
                                    <div class="row">
                                        <div class="col-xs-12 col-md-12">
                                            <div>名称/材质/规格：{{item.Commodity.Name}}/{{item.Commodity.Standard}}/{{item.Commodity.Format}}</div>
                                            <div>单价：{{item.Price | number:2}}/t</div>
                                            <div>数量：{{item.Count}}</div>
                                            <div>总质量：{{item.Weight | number:3}}t</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="panel-footer">
                                    <div>总价：{{item.Price | number:2}}*{{item.Weight | number:3}}t={{item.Price*item.Weight | number:2}}</div>
                                </div>
                            </div>
                            <div class="row text-left container-fluid">
                                <h4 style="display: inline-block">总价：{{orderdetaildata.Total | number:2}}</h4>
                            </div>
                            <div class="row text-right">
                                <button ng-if="orderdetaildata.State == 7 && (orderdetaildata.OrderType == 0 ||orderdetaildata.Provider.ProviderType==0)" type="button" class="btn btn-danger" ng-click="confirm(0)">直发确认计划单</button>
                                <button ng-if="orderdetaildata.State == 7 && orderdetaildata.Provider.ProviderType!=0" type="button" class="btn btn-danger" ng-click="confirm(4)">库提确认计划单</button>
                                <button ng-if="orderdetaildata.State == 7" type="button" class="btn btn-warning" ng-click="cancel()">取消计划单</button>
                                <button ng-if="orderdetaildata.State == 2 || orderdetaildata.State == 3 || orderdetaildata.State == 4 || orderdetaildata.State == 5" type="button" class="btn btn-danger" data-toggle="modal" data-target="#shangchuan">上传收货凭证</button>
                                <button ng-if="orderdetaildata.State == 1" type="button" class="btn btn-danger" ng-click="sendok()">确认发货</button>
                                <button ng-if="(orderdetaildata.State == 1 || orderdetaildata.State == 2) && !orderdetaildata.IsDelivery" type="button" class="btn btn-success" data-toggle="modal" data-target="#dlg">更改送货信息</button>
                                <button ng-if="orderdetaildata.State == 2 && !orderdetaildata.IsToDeliveryList  && orderdetaildata.Provider.ProviderType!=0" type="button" class="btn btn-danger" ng-click="changeorderdata(4)">生成出库单</button>
                                <button ng-if="orderdetaildata.State == 2 && !orderdetaildata.IsToDeliveryList && orderdetaildata.OrderType == 0" type="button" class="btn btn-danger" ng-click="changeorderdata(0)">设置直发实重</button>
                                <button type="button" class="btn btn-success" ng-click="goorderList()">返回计划单列表</button>
                                <button ng-if="(orderdetaildata.OrderType == 0 ||orderdetaildata.Provider.ProviderType==0) && (orderdetaildata.State == 1||orderdetaildata.State == 2)" type="button" class="btn btn-success" ng-click="gocaigoudan()">跳转到采购单</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    angular.module('app')
            .controller("FieldManDetailC", function ($scope, $state, $http, $stateParams) {
                $scope.id = JSON.parse($stateParams.orderid);
                $scope.GetReceiptdata = false;
                $scope.myurl = '../api/Upload?orderId='+$scope.id;
                //获取计划单详细数据

                $http({
                    url:"../api/Order/Detail?id="+$scope.id,
                    method:"GET"
                })
                        .then(function (res) {
                            $scope.orderdetaildata = res.data;
                            console.log($scope.orderdetaildata);
                        })
                        .then(function (error) {
                            if(error){
                                console.log("error");
                            }
                        });
                //获取收货凭证路径
                $http({
                    url:"../api/Order/GetReceipt?orderId="+$scope.id,
                    method:"GET"
                })
                        .then(function (res) {
//                            console.log(res.data.Data);
                            if (res.data.Data.length > 0){
                                $scope.GetReceiptdata = res.data.Data;
//                                console.log($scope.GetReceiptdata);
                            }else{
                                console.log("meishuju")
                            }
                        })
                        .then(function (error) {
                            if(error){
                                console.log("error");
                            }
                        });
                //取消计划单
                $scope.cancel = function () {
                    $http({
                        url: "../api/Order/Cancel?id=" + $scope.id,
                        method: "POST"
                    })
                            .then(function () {
                                alert("已取消");
                                $state.go('app.FieldMan_FieldManList');
                                 window.location.reload()
                            })
                            .then(function (error) {
                                if (error) {
                                    console.log("error");
                                }
                            });
                };
                //更改商品信息
                $scope.changeorderdata = function(type1){
                    $state.go('app.FieldMan_FieldManEdit',{
                        orderid:JSON.stringify($scope.id),
                        type:JSON.stringify(type1)
                    });
                };
                //查看大图
                $scope.editReceipt = function(item){
                    $scope.editReceiptdata = item
                };
                //确认计划单
                $scope.confirm = function(type){
                    if(type == 4){
                        $scope.myurl1 = "../api/FieldMan/ConfirmOrder?orderId="+$scope.id;
                        window.location.reload();
                    }else if(type == 0){
                        $scope.myurl1 = "../api/FieldMan/OrderPurchasingConfirm?orderId="+$scope.id;
                            window.location.reload();
                    }
                    $http({
                        url:$scope.myurl1,
                        method:"PUT"
                    })
                            .then(function (res) {
                                if (res.State <= 0) {
                                    alert(res.Msg);
                                } else {
                                    alert("已确认");

                                    $state.go('app.FieldMan_FieldManDetail', {
                                        orderid: JSON.stringify($scope.id)
                                    }); window.location.reload()
                                }
                            })
                            .then(function (error) {
                                if(error){
                                    console.log("error");
                                }
                            });
                };
                //确认发货
                $scope.sendok = function(){
                    $http({
                        url:"../api/FieldMan/ConfirmSend?orderId="+$scope.id,
                        method:"PUT"
                    })
                            .then(function (res) {
                                if (res.data.State <= 0) {
                                    alert(res.data.Msg);
                                } else {
                                    alert("已确认");
                                    $state.go('app.FieldMan_FieldManDetail', {
                                        orderid: JSON.stringify($scope.id)
                                    });
                                    window.location.reload();
                                }
                            })
                            .then(function (error) {
                                if(error){
                                    console.log("error");
                                }
                            });
                };
                //保存用户信息
                $scope.okchange = function(){
                    $http.post('../api/OrderManager/OrderBaseEdit', $scope.orderdetaildata)
                            .success(function (res) {
                                if (!res) {
                                    alert("修改失败");
                                } else {
                                    alert("修改成功");
                                    $('#dlg').modal("hide");
                                    $state.go('app.FieldMan_FieldManDetail', {
                                        orderid: JSON.stringify($scope.id)
                                    }); window.location.reload()
                                }
                            });
                };
                //返回驻场计划单列表
                $scope.goorderList = function(){
                    $state.go('app.FieldMan_FieldManList');
                };
                //返回采购计划单列表
                $scope.gocaigoudan =function(){
                    $state.go('app.Purchasing_MyDetailPurchase',{
                        orderid: JSON.stringify($scope.id),
                        type:1
                    });
                };

                $scope.bar = $(".bar");//进度条
                $scope.percent = $('.percent');//获取上传百分比
                $scope.showimg = $('.showimg');//显示图片的div
                $scope.progress = $('.progress');//显示进度的div
                $scope.files = $('.files');//文件上传控件的input元素
                $scope.btn = $('.btn span'); //按钮文本
                $scope.gosubmit2 = function (){
                    $("#myupload").ajaxSubmit({
                        dataType :'json',//返回数据类型
                        beforeSend:function(){
                            $scope.showimg.empty();
                            $scope.progress.show();
                            $scope.percentVal = '0%';
                            $scope.bar.width($scope.percentVal);
                            $scope.percent.html($scope.percentVal);
                            $scope.btn.html('上传中..');
                        },
                        //更新进度条事件处理代码
                        uploadProgress:function(event,position,total,percentComplete){
                            $scope.percentVal = percentComplete + '%';
                            $scope.bar.width($scope.percentVal);
                            $scope.percent.html($scope.percentVal);
                        },
                        success:function(data){//图片上传成功时
                            if(data){
                                alert("上传成功");
                                $('#shangchuan').modal("hide");
                                $state.go('app.FieldMan_FieldManDetail', {
                                    orderid: JSON.stringify($scope.id)
                                });
                            }
                        },
                        error:function(xhr){
                            $scope.btn.html('上传失败');
                            $scope.bar.width('0');
                            $scope.files.html(xhr.responseText);
                        }
                    });
                };
            })
</script>